﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cofe.Core.Property
{
    /// <summary>
    /// Cached version of IPropertyProvider, support CacheProperties, and 
    /// cache any cachable properties by using SetPropertyAsync.
    /// </summary>
    public interface IPropertyCache : IPropertyProvider
    {
        bool CanCache(object property);

        /// <summary>
        /// Return a list of changed properties (using SetPropertyAsync()) after last ResetChanges() method called. 
        /// </summary>
        List<object> ChangedProperties { get; }

        List<object> CachedProperties { get; }

        /// <summary>
        /// Call ChangedProperties.Clear()
        /// </summary>
        void ResetChanges();

  
        /// <summary>
        /// Remove all cached properties, except properties included in "excludedProperties". 
        /// Also ResetChanges() as well.
        /// </summary>
        /// <param name="filter">If not specify, reset all properties, otherwise reset only properties where filter(prop) = true.</param>
        void ResetCache(Func<object, bool> filter);

        ///// <summary>
        ///// Import properties from another Property Cache.
        ///// </summary>
        ///// <param name="propertyCaches"></param>
        //void ImportProperties(params IPropertyCache[] propertyCaches);

        /// <summary>
        /// Place the value of a property to cache, unlike SetPropertyAsync, doesnt add the property to CHangedProperties.
        /// </summary>        
        /// <param name="property"></param>
        /// <returns></returns>
        Task<bool> CachePropertyAsync(params PropertyPair[] propertyPair);

        Task WriteToDataStore();
        Task ReadFromDataStore();


        IPropertyCacheDictionary PropertyCacheDictionary { get; }
    }
}
